public class Solution {
    public int findMin(int[] nums) {
        int n = nums.length;
        if(n == 1){
            return nums[0];
        }
        int left = 0, right = n - 1;
        if(nums[left] < nums[right]){
            return nums[left];
        }
        while(left <= right){
            int mid = (left + right) / 2;
            if(mid == 0){
                return Math.min(nums[mid], nums[mid + 1]);
            }
            if(nums[mid] < nums[mid - 1]){
                return nums[mid];
            }
            if(nums[mid] < nums[0]){
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return 0;
    }
}
